package com.wtwd.wtwddevice.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wtwd.wtwddevice.mapper.SetBloodOxygenWarningMapper;
import com.wtwd.wtwddevice.model.entity.SetBloodOxygenWarning;
import com.wtwd.wtwddevice.model.entity.SetHeartRateWarning;
import com.wtwd.wtwddevice.service.ISetBloodOxygenWarningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SetBloodOxygenWarningServiceImpl extends ServiceImpl<SetBloodOxygenWarningMapper,SetBloodOxygenWarning> implements ISetBloodOxygenWarningService {
    @Autowired
    private SetBloodOxygenWarningMapper setBloodOxygenWarningMapper;
    @Override
    public int editSetBloodOxygenWarning(SetBloodOxygenWarning setBloodOxygenWarning) {
        SetBloodOxygenWarning setHeartRateWarningByDeviceId = setBloodOxygenWarningMapper.selectBloodOxygenWarningByDeviceId(setBloodOxygenWarning.getDeviceId());
        if(setHeartRateWarningByDeviceId == null){
            int insert = setBloodOxygenWarningMapper.insertSetBloodOxygenWarning(setBloodOxygenWarning);
        }
        return setBloodOxygenWarningMapper.updateSetBloodOxygenWarning(setBloodOxygenWarning);
    }

    /**
     *
     * @param deviceId
     * @param number
     * @return
     */
    @Override
    public boolean checkCommand(Long deviceId, String number) {
        return setBloodOxygenWarningMapper.selectCommand(deviceId,number) != null ? true : false;
    }

    @Override
    public int editState(Long deviceId, String number,Integer state) {
        return setBloodOxygenWarningMapper.updateState(deviceId,number,state);
    }
}
